# -*- coding:utf-8 -*-
__author__   = 'tommy'
__license__  = 'htcharge.com@2016-08-29'
__version__  = 'v1.0.0'

import json, qutils, qwaterdb, qwater

#获取卡的信息
def msgCardInfos(aCardInfos):
    tmpInfo             = {}
    tmpInfo["status"]   = 0
    tmpInfo["infos"]    = []

    tmpArr = aCardInfos.split("@@@")
    for cardInfo in tmpArr :
        tmpArrCard                  = cardInfo.split("&v;")
        tmpCardInfo                 = {}
        tmpCardInfo["card"]         = tmpArrCard[1]
        tmpCardInfo["suname"]       = tmpArrCard[2]
        tmpCardInfo["pn"]           = tmpArrCard[3]
        tmpCardInfo["inum"]         = tmpArrCard[4]
        tmpCardInfo["isex"]         = tmpArrCard[5]
        tmpCardInfo["ination"]      = tmpArrCard[6]
        tmpCardInfo["ibirth"]       = tmpArrCard[7]
        tmpCardInfo["iname"]        = tmpArrCard[8]
        tmpCardInfo["ctype"]        = tmpArrCard[9]
        tmpCardInfo["addr"]         = tmpArrCard[10]
        tmpCardInfo["coffi"]        = tmpArrCard[11]
        tmpCardInfo["cdealcount"]   = tmpArrCard[12]
        tmpCardInfo["cdeal"]        = tmpArrCard[13]
        tmpCardInfo["bala"]         = tmpArrCard[14]
        tmpCardInfo["stime"]        = tmpArrCard[15]
        tmpCardInfo["etime"]        = tmpArrCard[16]
        tmpCardInfo["msn"]          = tmpArrCard[17]

        tmpInfo["infos"].append(tmpCardInfo)

    return json.dumps(tmpInfo)

#使用的设备列表
def msgUsingList(aUsingList):
    tmpInfo             = {}
    tmpInfo["status"]   = 0
    tmpInfo["infos"]    = []

    tmpArr = aUsingList.split("@@@")
    del tmpArr[0]

    for devInfo in tmpArr :
        tmpArrDev               = devInfo.split("&v;")
        tmpDevInfo              = {}
        tmpDevInfo["posid"]     = tmpArrDev[1]      #加水机编号
        tmpDevInfo["paytype"]   = tmpArrDev[2]      #计价方式
        tmpDevInfo["ptone"]     = tmpArrDev[3]      #每吨单价
        tmpDevInfo["psec"]      = tmpArrDev[4]      #每秒单价
        tmpDevInfo["total"]     = tmpArrDev[5]      #消费金额
        tmpDevInfo["stime"]     = tmpArrDev[6]      #开始时间
        tmpDevInfo["stone"]     = tmpArrDev[7]      #开始表数
        tmpDevInfo["utone"]     = tmpArrDev[8]      #使用吨数
        tmpDevInfo["utime"]     = tmpArrDev[9]      #使用时间
        tmpDevInfo["dname"]     = tmpArrDev[10]     #设备名称
        tmpDevInfo["mincharge"] = tmpArrDev[11]     #最低消费
        tmpDevInfo["card"]      = tmpArrDev[12]     #加水卡号
        tmpDevInfo["iname"]     = tmpArrDev[13]     #卡主姓名
        tmpDevInfo["mac"]       = tmpArrDev[14]     #设备mac
        tmpDevInfo["sdelay"]    = tmpArrDev[15]     #开始延时
        tmpDevInfo["edelay"]    = tmpArrDev[16]     #结束延时
        tmpDevInfo["dstatus"]   = tmpArrDev[17]     #水表状态 0离线 1在线
        tmpDevInfo["dval"]      = tmpArrDev[18]     #当前表数
        tmpDevInfo["saleno"]    = tmpArrDev[19]     #订单编号
        
        tmpInfo["infos"].append(tmpDevInfo)

    return json.dumps(tmpInfo)

#根据经纬度获取的列表
def msgLocList(aLocList):
    tmpInfo             = {}
    tmpInfo["status"]   = 0
    tmpInfo["infos"]    = []

    tmpArr = aLocList.split("@@@")
    del tmpArr[0]

    for devInfo in tmpArr :
        tmpArrDev               = devInfo.split("&v;")
        tmpDevInfo              = {}
        tmpDevInfo["dname"]     = tmpArrDev[1]      #设备名称
        tmpDevInfo["posid"]     = tmpArrDev[2]      #加水机编号
        tmpDevInfo["paytype"]   = tmpArrDev[3]      #计价方式
        tmpDevInfo["ptone"]     = tmpArrDev[4]      #每吨单价
        tmpDevInfo["psec"]      = tmpArrDev[5]      #每秒单价
        tmpDevInfo["mac"]       = tmpArrDev[6]      #设备mac
        tmpDevInfo["sdelay"]    = tmpArrDev[7]      #开始延时
        tmpDevInfo["edelay"]    = tmpArrDev[8]      #结束延时
        tmpDevInfo["mincharge"] = tmpArrDev[9]      #最低消费
        tmpDevInfo["dstatus"]   = tmpArrDev[10]     #水表状态 0离线 1在线
        tmpDevInfo["dval"]      = tmpArrDev[11]     #当前表数
        
        tmpInfo["infos"].append(tmpDevInfo)

    return json.dumps(tmpInfo)

#获取单个设备的信息
def msgOneDev(aDevInfo):
    tmpInfo             = {}
    tmpInfo["status"]   = 0

    tmpArr = aDevInfo.split("@@@")

    tmpStrUnUsing           = tmpArr[0]
    tmpArrUnUsing           = tmpStrUnUsing.split("&v;")

    tmpInfo["dname"]        = tmpArrUnUsing[0]      #设备名称
    tmpInfo["posid"]        = tmpArrUnUsing[1]      #加水机编号
    tmpInfo["paytype"]      = tmpArrUnUsing[2]      #计价方式
    tmpInfo["ptone"]        = tmpArrUnUsing[3]      #每吨单价
    tmpInfo["psec"]         = tmpArrUnUsing[4]      #每秒单价
    tmpInfo["mac"]          = tmpArrUnUsing[5]      #设备mac
    tmpInfo["sdelay"]       = tmpArrUnUsing[6]      #开始延时
    tmpInfo["edelay"]       = tmpArrUnUsing[7]      #结束延时
    tmpInfo["mincharge"]    = tmpArrUnUsing[8]      #最低消费
    tmpInfo["dstatus"]      = tmpArrUnUsing[9]      #水表状态 0离线 1在线
    tmpInfo["dval"]         = tmpArrUnUsing[10]     #当前表数

    tmpStrUsing             = tmpArr[1]

    if tmpStrUsing and len(tmpStrUsing) > 0:
        tmpArrUsing         = tmpStrUsing.split("&v;")

        tmpInfo["total"]    = tmpArrUsing[1]        #消费金额
        tmpInfo["stime"]    = tmpArrUsing[2]        #开始时间
        tmpInfo["stone"]    = tmpArrUsing[3]        #开始表数
        tmpInfo["utone"]    = tmpArrUsing[4]        #使用吨数
        tmpInfo["utime"]    = tmpArrUsing[5]        #使用时间
        tmpInfo["card"]     = tmpArrUsing[6]        #加水卡号
        tmpInfo["iname"]    = tmpArrUsing[7]        #卡主姓名
        tmpInfo["saleno"]   = tmpArrUsing[8]        #订单编号
        tmpInfo["usestatus"]= tmpArrUsing[9]        #使用状态    

    return json.dumps(tmpInfo)

#获取订单列表的信息
def msgOrderList(aList):
    tmpInfo             = {}
    tmpInfo["status"]   = 0
    tmpInfo["infos"]    = []

    tmpArr = aList.split("@@@")
    del tmpArr[0]

    for dealInfo in tmpArr :
        tmpArrDeal              = dealInfo.split("&v;")
        tmpDealInfo                   = {}
        tmpDealInfo["saleno"]         = tmpArrDeal[1]
        tmpDealInfo["posid"]          = tmpArrDeal[2]
        tmpDealInfo["p_num"]          = tmpArrDeal[3]
        tmpDealInfo["start_tones"]    = tmpArrDeal[4]
        tmpDealInfo["tones"]          = tmpArrDeal[5]
        tmpDealInfo["seconds"]        = tmpArrDeal[6]
        tmpDealInfo["start_time"]     = tmpArrDeal[7]
        tmpDealInfo["stop_time"]      = tmpArrDeal[8]
        tmpDealInfo["p_second"]       = tmpArrDeal[9]
        tmpDealInfo["p_tones"]        = tmpArrDeal[10]
        tmpDealInfo["pay_type"]       = tmpArrDeal[11]
        tmpDealInfo["username"]       = tmpArrDeal[12]
        tmpDealInfo["stop_way"]       = tmpArrDeal[13]
        tmpDealInfo["card"]           = tmpArrDeal[14]
        tmpDealInfo["su_card"]        = tmpArrDeal[15]
        tmpDealInfo["stop_tones"]     = tmpArrDeal[16]
        tmpDealInfo["money"]          = tmpArrDeal[17]
        tmpDealInfo["be_money"]       = tmpArrDeal[18]
        tmpDealInfo["af_money"]       = tmpArrDeal[19]
        tmpDealInfo["phone"]          = tmpArrDeal[20]
        tmpDealInfo["card_type"]      = tmpArrDeal[21]
        tmpDealInfo["d_name"]         = tmpArrDeal[22]
        tmpDealInfo["mac"]            = tmpArrDeal[23]
        tmpDealInfo["mincharge"]      = tmpArrDeal[24]
        tmpDealInfo["market_name"]    = '5bm/5bee6I+c5biC5Zy6'
        tmpDealInfo["url"]            = 'www.ylflat.com'
        tmpDealInfo["hotline"]        = '400-888-8888'
        
        tmpInfo["infos"].append(tmpDealInfo)
                
    return json.dumps(tmpInfo)

#订单详情的信息
def msgOrderDetail(aList):
    tmpInfo             = {}
    tmpInfo["status"]   = 0
    tmpInfo["infos"]    = []

    tmpArrDetail        = aList.split("&v;")

    tmpDetailInfo                   = {}
    tmpDetailInfo["saleno"]         = tmpArrDetail[0]
    tmpDetailInfo["posid"]          = tmpArrDetail[1]
    tmpDetailInfo["p_num"]          = tmpArrDetail[2]
    tmpDetailInfo["start_tones"]    = tmpArrDetail[3]
    tmpDetailInfo["tones"]          = tmpArrDetail[4]
    tmpDetailInfo["seconds"]        = tmpArrDetail[5]
    tmpDetailInfo["start_time"]     = tmpArrDetail[6]
    tmpDetailInfo["stop_time"]      = tmpArrDetail[7]
    tmpDetailInfo["p_second"]       = tmpArrDetail[8]
    tmpDetailInfo["p_tones"]        = tmpArrDetail[9]
    tmpDetailInfo["pay_type"]       = tmpArrDetail[10]
    tmpDetailInfo["username"]       = tmpArrDetail[11]
    tmpDetailInfo["stop_way"]       = tmpArrDetail[12]
    tmpDetailInfo["card"]           = tmpArrDetail[13]
    tmpDetailInfo["su_card"]        = tmpArrDetail[14]
    tmpDetailInfo["stop_tones"]     = tmpArrDetail[15]
    tmpDetailInfo["money"]          = tmpArrDetail[16]
    tmpDetailInfo["be_money"]       = tmpArrDetail[17]
    tmpDetailInfo["af_money"]       = tmpArrDetail[18]
    tmpDetailInfo["phone"]          = tmpArrDetail[19]
    tmpDetailInfo["card_type"]      = tmpArrDetail[20]
    tmpDetailInfo["d_name"]         = tmpArrDetail[21]
    tmpDetailInfo["mac"]            = tmpArrDetail[22]
    tmpDetailInfo["mincharge"]      = tmpArrDetail[23]
    tmpDetailInfo["market_name"]    = '5bm/5bee6I+c5biC5Zy6'
    tmpDetailInfo["url"]            = 'www.ylflat.com'
    tmpDetailInfo["hotline"]        = '400-888-8888'
        
    tmpInfo["infos"]                = tmpDetailInfo
        
    return json.dumps(tmpInfo)

def msgError(aErr, aMsg):
    tmpMsgRetsult = {}
    tmpMsgRetsult["status"] = int(aErr)
    tmpMsgRetsult["msg"] = qutils.base64Encode(str(aMsg))
    qutils.rctLogger.info(tmpMsgRetsult)
    return json.dumps(tmpMsgRetsult)

def msgOk():
    tmpMsgRetsult = {}
    tmpMsgRetsult["status"] = 0
    qutils.rctLogger.info(tmpMsgRetsult)
    return json.dumps(tmpMsgRetsult)


